package com.alex.sitegrabber.tools;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;

public class Replace {
	public static void main(String[] args) throws Exception {
		String page = FileUtils.readFileToString(new File("/tmp/site/index.html"));
		
		Pattern pattern = Pattern.compile("href=\"(/mov/[^\"]+)\"");
		Matcher matcher = pattern.matcher(page);
		
		int id = 1000;
		
		int end = 0;
		StringBuilder sb = new StringBuilder();
		matcher = pattern.matcher(page);
		while (matcher.find()) {
			sb.append(page.substring(end, matcher.start(1)));
			end = matcher.end(1);
			sb.append("/cgi-bin/crtr/out.cgi?id=" + (id++) + "&l=thumb");
		}
		sb.append(page.substring(end));
		FileUtils.writeStringToFile(new File("/tmp/site/index2.html"), sb.toString());
	}
}
